// Generated by CoffeeScript 2.5.1
var app;

import {
  createApp
} from '/scripts/vue.esm-browser.prod.min.js';

Array.prototype.shuffle = function() {
  var i, item, j, k, len, ref, results;
  ref = this;
  results = [];
  for (i = k = 0, len = ref.length; k < len; i = ++k) {
    item = ref[i];
    j = i + Math.floor(Math.random() * (this.length - i));
    this[i] = this[j];
    results.push(this[j] = item);
  }
  return results;
};

Array.prototype.splitChunks = function(size) {
  var i, k, ref, ref1, results;
  results = [];
  for (i = k = 0, ref = this.length, ref1 = size; ref1 !== 0 && (ref1 > 0 ? k < ref : k > ref); i = k += ref1) {
    results.push(this.slice(i, i + size));
  }
  return results;
};

app = createApp({
  data: function() {
    return {
      input: '',
      grid: [],
      gridSize: 3,
      bingoGenerated: false
    };
  },
  computed: {
    phrases: function() {
      return this.input.split('\n').filter((phrase) => {
        return phrase;
      });
    },
    enoughPhrases: function() {
      return this.phrases.length >= this.gridSize * this.gridSize;
    }
  },
  methods: {
    generate: function() {
      var phrases, row, text;
      phrases = this.phrases;
      phrases.shuffle();
      phrases = phrases.slice(0, this.gridSize * this.gridSize);
      this.grid = (function() {
        var ref, results;
        ref = phrases.splitChunks(this.gridSize);
        results = [];
        for (row of ref) {
          results.push((function() {
            var results1;
            results1 = [];
            for (text of row) {
              results1.push({
                text,
                crossed: false
              });
            }
            return results1;
          })());
        }
        return results;
      }).call(this);
      return this.bingoGenerated = true;
    }
  },
  mounted: function() {
    var params;
    params = new URLSearchParams(window.location.search);
    if (params.has('file')) {
      fetch(params.get('file')).then((response) => {
        return response.text();
      }).then((text) => {
        return this.input = text;
      });
    }
    if (params.has('size')) {
      return this.gridSize = Number(params.get('size'));
    }
  }
});

app.mount(document.body);
